<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
		"http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<title>doh.robot Validation Test</title>

		<style>
			@import "../../../util/doh/robot/robot.css";
		</style>

		<!-- required: dojo.js -->
		<script type="text/javascript" src="../../../dojo/dojo.js"
			djConfig="isDebug: true, parseOnLoad: true"></script>
			
		<!-- functions to help test -->
		<script type="text/javascript" src="../helpers.js"></script>

		<script type="text/javascript">
			dojo.require("dijit.dijit"); // optimize: load dijit layer
			dojo.require("dijit.robotx");

			dojo.addOnLoad(function(){
				doh.robot.initRobot('../test_Menu.html');

				doh.register("dijit.MenuBar mouse tests", [

					{
						name: "mouse over file MenuBarItem",
						timeout: 4000,
						runTest: function(){
							var d = new doh.Deferred();

							// Check initial conditions
							doh.f(dojo.hasClass("file", "dijitMenuItemHover"), "File MenuBarItem doesn't have hover effect");
							doh.t(isHidden("fileMenu"), "File menu is hidden");						

							// Move over the File MenuBarItem
							doh.robot.mouseMoveAt("file", 500);

							doh.robot.sequence(d.getTestCallback(function(){
								// The "File" MenuBarItem should be highlighted
								doh.t(dojo.hasClass("file", "dijitMenuItemHover"),
									"File MenuBarItem should have hover effect, actual class is: " + dojo.byId("file").className);
	
								// However, just moving over the MenuBarItem shouldn't have opened the menu
								doh.t(isHidden("fileMenu"), "File menu is hidden");						
							}), 1000);	// 1000ms == give IE time to make that backgroune iframe
	
							return d;
						}
					},

					{
						name: "click on file MenuBarItem",
						timeout: 4000,
						runTest: function(){
							var d = new doh.Deferred();
	
							doh.robot.mouseClick({left: true}, 500);
							
							doh.robot.sequence(d.getTestCallback(function(){
								// The "File" MenuBarItem should have the selected class in addition to the hover
								// class
								doh.t(dojo.hasClass("file", "dijitMenuItemHover"),
									"File MenuBarItem should have hover effect, actual class is: " + dojo.byId("file").className);
								doh.t(dojo.hasClass("file", "dijitMenuItemSelected"),
									"File MenuBarItem should have selected class, actual class is: " + dojo.byId("file").className);

								// And the file menu should be visible
								doh.t(isVisible("fileMenu"), "File menu is visible");						
								
								// And the first item in the file menu should be selected
								doh.t(dojo.hasClass("new", "dijitMenuItemSelected"),
									"New MenuItem should have selected class, actual class is: " + dojo.byId("new").className);
							}), 1000);
	
							return d;
						}
					},

					{
						name: "hover edit menu item",
						timeout: 4000,
						runTest: function(){
							var d = new doh.Deferred();
	
							doh.robot.mouseMoveAt("edit", 500);
							
							doh.robot.sequence(d.getTestCallback(function(){
								// Since we've already activated the MenuBar by clicking "File",
								// hovering over "Edit" should automatically show the edit menu
								doh.t(isVisible("editMenu"), "Edit menu is visible");
								
								// And also, the file menu should have disappeared
								doh.t(isHidden("fileMenu"), "File menu is hidden");						
							}), 500);
	
							return d;
						}
					},

					{
						name: "move to copy",
						timeout: 4000,
						runTest: function(){
							var d = new doh.Deferred();
	
							doh.robot.mouseMoveAt("copy", 500);
							
							doh.robot.sequence(d.getTestCallback(function(){
								doh.f(dojo.hasClass("edit", "dijitMenuItemHover"),
									"Edit MenuBarItem shouldn't have hover effect anymore, actual class is: " + dojo.byId("edit").className);
								doh.t(dojo.hasClass("edit", "dijitMenuItemSelected"),
									"Edit MenuBarItem should still have selected class, actual class is: " + dojo.byId("edit").className);

								doh.t(dojo.hasClass("copy", "dijitMenuItemHover"),
									"Copy Menu item should have hover effect, actual class is: " + dojo.byId("copy").className);
								doh.t(dojo.hasClass("copy", "dijitMenuItemSelected"),
									"Copy Menu item should have selected effect, actual class is: " + dojo.byId("copy").className);
							}), 500);
	
							return d;
						}
					},

					{
						name: "click copy",
						timeout: 4000,
						runTest: function(){
							var d = new doh.Deferred();

							var clicked = false;
							dijit.byId("copy").onClick = function(){ clicked = true; };

							doh.robot.mouseClick({left: true}, 500);
							
							doh.robot.sequence(d.getTestCallback(function(){
								doh.t(clicked, "copy was clicked");
								doh.t(isHidden("editMenu"), "edit menu disappeared");						
								doh.f(dojo.hasClass("edit", "dijitMenuItemSelected"),
									"Edit MenuBarItem should no longer have selected effect, actual class is: " + dojo.byId("edit").className);
							}), 500);
	
							return d;
						}
					}

					// TODO: I think focus should go back to menubar... except that would open the menu again?
					// Anyway, tests below commented out until #8624 is dealt with
/****
					{
						name: "mouse over file MenuBarItem again",
						timeout: 4000,
						runTest: function(){
							var d = new doh.Deferred();
	
							// Check initial conditions
							doh.f(dojo.hasClass("file", "dijitMenuItemHover"), "File MenuBarItem doesn't have hover effect");
							doh.t(isHidden("fileMenu"), "File menu is hidden");						
							
							// Move over the File MenuBarItem
							doh.robot.mouseMoveAt("file", 500);
	
							doh.robot.sequence(d.getTestCallback(function(){
								// The "File" MenuBarItem should be highlighted
								doh.t(dojo.hasClass("file", "dijitMenuItemHover"),
									"File MenuBarItem should have hover effect, actual class is: " + dojo.byId("file").className);
	
								// However, it shouldn't be "selected", and
								// just moving over the MenuBarItem shouldn't have opened the menu,
								// given that after clicking above, the MenuBar should have reverted to it's
								// "dormant" state so that it needs to be clicked again before menus show up automatically
								doh.f(dojo.hasClass("file", "dijitMenuItemSelected"),
									"File MenuBarItem shouldn't have selected effect, actual class is: " + dojo.byId("file").className);
								doh.t(isHidden("fileMenu"), "File menu is hidden");						
							}), 500);

							return d;
						}
					}
****/
				]);


				doh.register("Navigation menu mouse tests", [

					
					{
						name: "mouse over enabled submenu",
						timeout: 4000,
						runTest: function(){
							var d = new doh.Deferred();

							// Check initial conditions
							doh.f(dojo.hasClass("navMenuPopupItem1", "dijitMenuItemHover"), "navMenuPopupItem1 MenuItem doesn't have hover effect");
							doh.t(isHidden("navMenuSub1"), "sub menu is hidden");						

							doh.robot.mouseMoveAt("navMenuPopupItem1", 500);

							doh.robot.sequence(d.getTestCallback(function(){
								// The "enabled submenu" MenuItem should be highlighted
								doh.t(dojo.hasClass("navMenuPopupItem1", "dijitMenuItemHover"),
									"'Enabled Submenu' MenuItem should have hover effect, actual class is: " + dojo.byId("navMenuPopupItem1").className);
	
								// However, just moving over the MenuItem shouldn't have opened the menu
								doh.t(isHidden("navMenuSub1"), "sub menu is hidden");						
							}), 500);
	
							return d;
						}
					},

					{
						name: "open submenu",
						timeout: 4000,
						runTest: function(){
							var d = new doh.Deferred();
	
							doh.robot.mouseClick({left: true}, 500);
							
							doh.robot.sequence(d.getTestCallback(function(){
								doh.t(dojo.hasClass("navMenuPopupItem1", "dijitMenuItemHover"),
									"'Enabled Submenu' MenuItem should have hover effect, actual class is: " + dojo.byId("navMenuPopupItem1").className);
								doh.t(dojo.hasClass("navMenuPopupItem1", "dijitMenuItemSelected"),
									"'Enabled Submenu' MenuItem should have selected effect, actual class is: " + dojo.byId("navMenuPopupItem1").className);

								// And the sub menu should be visible
								doh.t(isVisible("navMenuSub1"), "sub menu is visible");						
								
								// And the first item in the sub menu should be selected
								doh.t(dojo.hasClass("navMenuSub1_item1", "dijitMenuItemSelected"),
									"first item in sub menu should have selected class, actual class is: " + dojo.byId("new").className);
							}), 1000);
	
							return d;
						}
					},
					
					{
						name: "toggle CheckedMenuItem",
						timeout: 3000,
						runTest: function(){
							var d = new doh.Deferred();

							doh.f(dijit.byId("checked2").attr('checked'), "not initially checked");

							doh.robot.mouseMoveAt("checked2", 500);
							doh.robot.mouseClick({left: true}, 500);
							
							doh.robot.sequence(d.getTestCallback(function(){
								doh.t(dijit.byId("checked2").attr('checked'), "now it's checked");				
							}), 500);
	
							return d;
						}
					}
				]);

				doh.register("Context menu mouse tests", [
					{
						name: "open global context menu (mouse)",
						timeout: 3000,
						runTest: function(){
							var d = new doh.Deferred();

							var menu = dijit.byId("windowContextMenu");
							
							doh.t(isHidden(menu), "menu should be initially hidden");						

							// click random point on screen
							doh.robot.mouseMoveAt("link", 500);
							doh.robot.mouseClick({right: true}, 500);

							doh.robot.sequence(d.getTestCallback(function(){
								doh.t(isVisible(menu), "menu is now shown");						
								
								var linkCoords = dojo.coords("link");
									menuCoords = dojo.coords(menu.domNode);

								doh.t(menuCoords.x > linkCoords.x, "to right of link left edge")
								doh.t(menuCoords.x < linkCoords.x + linkCoords.w, "to left of link right edge")
								doh.t(menuCoords.y > linkCoords.y, "starts below top of link")
								doh.t(menuCoords.y < linkCoords.x + linkCoords.h, "starts above bottom of link")				
							}), 500);
	
							return d;
						}
					},

					{
						name: "close global context menu (mouse)",
						timeout: 4000,
						runTest: function(){
							var d = new doh.Deferred();

							var menu = dijit.byId("windowContextMenu");
							
							// close menu from above test
							doh.robot.mouseMove(2, 2, 100);
							doh.robot.mouseClick({left: true}, 100);

							doh.robot.sequence(d.getTestCallback(function(){
								doh.t(isHidden(menu), "menu should be hidden again");						
							}), 500);
	
							return d;
						}
					}

					]);

				doh.run();
			});
		</script>
	</head>
</html>
<html><body></body></html>